#ifndef PLAYLIST_H
#define PLAYLIST_H
#include<QtGui>
#include<phonon>

class TrackPlayer;
class TrackInfoWidget;
namespace Ui {
class PlayListWidget;
}

enum PlayMode{
    ORDINALPLAY=0,
    LISTREPEAT,
    TRACKREPEAT,
    RANDOMPLAY
};

class PlayListWidget:public QWidget
{
    Q_OBJECT
public:
    explicit PlayListWidget(QWidget* parent=0);
    void setPlayer(TrackPlayer *player);
    void setPlayMode(PlayMode mode);
public slots:
    void addTrack(const QString &dirName,const QStringList &fileNames,bool save=true);
    void addTrack(const QStringList &tracks,const QStringList &path,bool save=true);
//    void delTrack(const QString &file);
    void playNextTrack();
    void playPrevTrack();
    void playCurrentTrack();
    void onAboutToFinished();
    void stop();
    void playOrPause(bool);
protected:
    void closeEvent(QCloseEvent *ce);
private:
    PlayMode playMode;

    TrackPlayer *player;
    Ui::PlayListWidget *ui;
    QWidget *mainWindow;
    TrackInfoWidget *trackInfoWidget;
    QMap<QString,QString> queue;
    QMap<QString,QString> artist;
    QMap<QString,QString> title;
    QStringList trackFiles;
    void creatActions();
    void creatConnections();
    void readPlayList();
    void savePLayList();
//    bool waitForMediaObjectToLoad(Phonon::MediaObject *obj,int timeoutMsec);

//    QToolButton* addToListBtn;
//    QToolButton* delFromListBtn;
//    QToolButton* sortListBtn;

    QAction* addTrackAct;
    QAction* addDirectoryAct;
    QMenu *addBtnMenu;
    QAction *delCurrentTrackAct;
    QAction *viewTrackInfoAct;
    QAction *clearPlayListAct;
    QAction *sortByArtistAct;
    QAction *sortByFileNameAct;
    QAction *sortByAlbumAct;
    QAction *sortByTitleAct;
    QMenu *trackMenu;
    QMenu *delMenu;
    QMenu *sortMenu;
private slots:
    void onItemDbleClicked(QTreeWidgetItem *item,int column);
    void onAddTrackTriggered();
    void onAddDirTriggered();
    void onContextMenuRequest(const QPoint&);
    void onDelCurrentTrackTriggered();
    void onViewTrackInfoTriggered();
    void onClearPlayListTriggered();
    void onSortByFileNameTriggered();
    void onSortByTitleTriggered();
    void onSortByAlbumTriggered();
    void onSortByArtistTriggered();
signals:
    void playTrackRequest(const QString &fileName);
    void enqueueRequest(const QString &fileName);
    void closeRequest();
};
#endif // PLAYLIST_H
